package com.example.demo1;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");//获取用户名
        String password = req.getParameter("password");//获取密码
        String hobby = req.getParameter("hobby");//获取兴趣爱好
        String[] hobby1 =req.getParameterValues("hobby");//获取请求的参数（多个值的时候使用)
        System.out.println(username);
        System.out.println(password);
        System.out.println(hobby1);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决post请求中文乱码的问题
        req.setCharacterEncoding("UTF-8");
        String username = req.getParameter("username");//获取用户名
        String password = req.getParameter("password");//获取密码
        String hobby = req.getParameter("hobby");//获取兴趣爱好
        String[] hobby1 =req.getParameterValues("hobby");//获取请求的参数（多个值的时候使用)
        System.out.println(username);
        System.out.println(password);
        System.out.println(hobby1);
    }
}
